package com.risk.web.controller.tk;

import com.alibaba.fastjson2.JSONObject;
import com.risk.common.core.controller.BaseController;
import com.risk.common.core.domain.AjaxResult;
import com.risk.common.core.page.TableDataInfo;
import com.risk.kernel.domain.TkTaskCaseResult;
import com.risk.kernel.service.TkTaskCaseResultServiceI;
import com.risk.kernel.vo.TkTaskCaseInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: Liwen
 * @createTime: 2025/1/23
 * @description:
 */
@RestController
@RequestMapping(value = "/tk/case/result")
public class TkTaskCaseResultController extends BaseController {
    @Autowired
    private TkTaskCaseResultServiceI tkTaskCaseResultService;

    /**
     * 查询列表
     */
    @PreAuthorize("@ss.hasPermi('tk:case:result:list')")
    @GetMapping("/list/{rid}")
    public TableDataInfo list(@PathVariable String rid) {
        List<TkTaskCaseInfoVo> list = tkTaskCaseResultService.selectTkTaskCaseResultList(rid);
        return getDataTable(list);
    }

    /**
     * 导出列表
     */
//    @PreAuthorize("@ss.hasPermi('kf:result:export')")
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, TkTaskCaseResult tkTaskCaseResult) {
//        List<TkTaskCaseResult> list = tkTaskCaseResultService.selectTkTaskCaseResultList(tkTaskCaseResult);
//        ExcelUtil<TkTaskCaseResult> util = new ExcelUtil<>(TkTaskCaseResult.class);
//        util.exportExcel(response, list, "【请填写功能名称】数据");
//    }

    /**
     * 获取详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(tkTaskCaseResultService.selectTkTaskCaseResultById(id));
    }

    /**
     * 新增
     */
    @PostMapping
    public AjaxResult add(@RequestBody TkTaskCaseResult tkTaskCaseResult) {
        return toAjax(tkTaskCaseResultService.insertTkTaskCaseResult(tkTaskCaseResult));
    }

    /**
     * 修改
     */
    @PutMapping
    public AjaxResult edit(@RequestBody TkTaskCaseResult tkTaskCaseResult) {
        return toAjax(tkTaskCaseResultService.updateTkTaskCaseResult(tkTaskCaseResult));
    }

    /**
     * 删除
     */
    @PreAuthorize("@ss.hasPermi('tk:case:result:remove')")
    @DeleteMapping("/remove/{resultId}")
    public AjaxResult remove(@PathVariable String resultId) {
        return toAjax(tkTaskCaseResultService.deleteTkTaskCaseResultByIds(resultId));
    }

    /**
     * 根据caseId查询所有执行过的用例名称
     */
//    @PreAuthorize("@ss.hasPermi('tk:case:result:query:caseName')")
    @GetMapping("/getCaseResultName/{caseId}")
    public TableDataInfo getCaseResultName(@PathVariable String caseId) {
        List<JSONObject> list = tkTaskCaseResultService.getCaseResultName(caseId);
        return getDataTable(list);
    }




}
